package com.overseasShopping.Biz.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.overseasShopping.Base.DAO.DetailUserDAO;
import com.overseasShopping.Base.DAO.UserDAO;
import com.overseasShopping.Biz.UserBiz;
import com.overseasShopping.pojo.DetailUser;
import com.overseasShopping.pojo.User;

public class UserBizImpl implements UserBiz{
	private UserDAO userDAO=null;
	private DetailUserDAO detailUserDAO=null;
	
	
	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}
	
	




	public void setDetailUserDAO(DetailUserDAO detailUserDAO) {
		this.detailUserDAO = detailUserDAO;
	}






	public void addUser(User user) {
		userDAO.save(user);
		
	}


	public User getUser(String id) {
		return userDAO.getUser(id);
	}


	public List<DetailUser> getFriends(String userId) {
		List<User> friends= userDAO.getFriends(userId);
		List<DetailUser>friendsDetail=new ArrayList<DetailUser>();
		for (int i = 0; i < friends.size(); i++) {
			friendsDetail.add(detailUserDAO.get(friends.get(i).getUserId()));
		}
		return friendsDetail;
	}


	public List<DetailUser> getBlackList(String userId) {
		List<User> blackList= userDAO.getBlackFriends(userId);
		List<DetailUser> blackListDetail=new ArrayList<DetailUser>();
		for (int i = 0; i < blackList.size(); i++) {
			blackListDetail.add(blackList.get(i).getDetailUser());
		}
		return blackListDetail;
	}

	public User updatePassword(User user) {
		userDAO.update(user);
		return login(user.getUserId(), user.getPassword());
	}

	public User login(String id,String password) {
		return userDAO.login(id, password);
	}

	public void addFriend(String uid, String fid) {
		userDAO.addFriend(uid,fid);
	}
	
	public void deleteBlackUser(String uid, String fid) {
		userDAO.deleteBlackUser(uid,fid );
	}

	public void deleteFriend(String uid, String fid) {
		userDAO.deleteFriend(uid, fid);
		
	}

	public void addBlackList(String uid, String bid) {
		userDAO.addBlackList(uid, bid);
	}

	public void updateUser(User user) {
		userDAO.update(user); 
	}

}
